/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.qdu.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.qdu.util.DatabaseUtil;

/**
 *
 * @author 39370
 */
public class Recommend {

    public List get6NewBook() {
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        List list = new ArrayList();

        try {
            con = DatabaseUtil.getConnection();
            ps = con.prepareStatement("select top(6) book_name,book_picturepath,book_price,book_id from bookinformation where book_type='最新' order by book_id desc");
            rs = ps.executeQuery();
            while (rs.next()) {
                List list2 = new ArrayList();
                list2.add(rs.getString(1));
                list2.add(rs.getString(2));
                list2.add(rs.getString(3));
                list2.add(rs.getString(4));
                
                list.add(list2);

            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DatabaseUtil.close(rs, ps, con);
        }
        return list;
    }

     public List getAllBook() {
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        List list = new ArrayList();

        try {
            con = DatabaseUtil.getConnection();
            ps = con.prepareStatement("select  book_name,book_picturepath,book_price,book_id,book_author,book_publisher,book_type from bookinformation  order by book_id desc");
            rs = ps.executeQuery();
            while (rs.next()) {
                List list2 = new ArrayList();
                list2.add(rs.getString(1));
                list2.add(rs.getString(2));
                list2.add(rs.getString(3));
                list2.add(rs.getString(4));
                list2.add(rs.getString(5));
                list2.add(rs.getString(6));
                list2.add(rs.getString(7));
                list.add(list2);

            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DatabaseUtil.close(rs, ps, con);
        }
        return list;
    }
    public List getAllNewBook() {
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        List list = new ArrayList();

        try {
            con = DatabaseUtil.getConnection();
            ps = con.prepareStatement("select  book_name,book_picturepath,book_price,book_id,book_author,book_publisher,book_type from bookinformation where book_type='最新' order by book_id desc");
            rs = ps.executeQuery();
            while (rs.next()) {
                List list2 = new ArrayList();
                list2.add(rs.getString(1));
                list2.add(rs.getString(2));
                list2.add(rs.getString(3));
                list2.add(rs.getString(4));
                list2.add(rs.getString(5));
                list2.add(rs.getString(6));
                list2.add(rs.getString(7));
                list.add(list2);

            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DatabaseUtil.close(rs, ps, con);
        }
        return list;
    }

    public List getBookType() {
        List list = new ArrayList();
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            con = DatabaseUtil.getConnection();
            ps = con.prepareStatement("select * from bookclassification");
            rs = ps.executeQuery();
            while (rs.next()) {
                list.add(rs.getString(2));
            }
            return list;
        } catch (Exception e) {
            e.printStackTrace();
            return list;
        } finally {
            DatabaseUtil.close(rs, ps, con);
        }
    }

    public List getTypeBooklist(String book_classification) {
        List list = new ArrayList();
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            con = DatabaseUtil.getConnection();
            ps = con.prepareStatement("select book_name,book_picturepath,book_price,book_id,book_author,book_publisher,book_type from bookinformation where book_classification=? order by book_id desc");
            ps.setString(1,book_classification);
            rs = ps.executeQuery();
            while (rs.next()) {
                List list2 = new ArrayList();
                list2.add(rs.getString(1));
                list2.add(rs.getString(2));
                list2.add(rs.getString(3));
                list2.add(rs.getString(4));
                list2.add(rs.getString(5));
                list2.add(rs.getString(6));
                list2.add(rs.getString(7));
                list.add(list2);
            }
            return list;
        } catch (Exception e) {
            e.printStackTrace();
            return list;
        } finally {
             DatabaseUtil.close(rs, ps, con);
        }
    }
}
